%script to perform a trainig and a test of models

clear all;
close all;

% %DEBUG: optimum values
%  Ps = [3 3;1 2;5 6;2 6;2 2];
%  Ws = [34.59; 7.556; 4.2476; 19.717; 29.217; 34.805];



%Y Target Variable
Y = csvread('Data\TestData\Y.csv');

%X rawdata training data set
X = csvread('Data\TestData\X.csv');

%feature scaling to avoid overflow
[X, mu, st] = featureScaling(X);

%split data
[m n] = size(X);
%get the testsize
len = round(0.7 * m);
%split into training data
Xtrain = X(1:len, :);
Ytrain = Y(1:len, :);
%split into test data
Xtest = X(len:end, :);
Ytest = Y(len:end,:);
trainingCost = zeros(10,1);
testCost =  zeros(10,1);

for it=1:10
    
    tic;
    
    %model 1
    [Poptim PCostO Woptim WCostO Coptim] = approach1(Ytrain, Xtrain, 400, 0.1, 1);
    trainingCost(it,1) =  Coptim;
    [H, cost] = modelPrediction(Ytest ,Xtest, Poptim, Woptim);
    testCost(it,1) = cost;
    
%     %model 2
%     [Woptim, WCostO] = approach2(Y, X, 7, 400, 0.01, 1);
%     trainingCost(it,1) = WCostO(end,1);
%     [H, cost] = modelPredictionAPP2(Ytest ,Xtest, 7, Woptim);
%     testCost(it,1) = cost;
    
    toc
    
end;
%prints
%print test cost
sprintf('mean Training cost: %0.4f', mean(trainingCost))
sprintf('std Training cost: %0.4f', std(trainingCost))

%print test cost
sprintf('mean Test cost: %0.4f', mean(testCost))
sprintf('std Test cost: %0.4f', std(testCost))

%linear regression training cost
figure,plot(WCostO);
%feature optimization traing cost
figure,plot(PCostO);
